import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { GoodsItem } from "../../common/GoodsItem";
import { ItemData } from "../../../resource/info/ItemData";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { Cache } from "../../../cache/Cache";
import { ShopOperType } from "../../shop/ShopOperType";
//class PetEquipItemRenderer
    
    export  class PetEquipItemRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.initStyle();
            this.mouseEnabled = true;
            this.mouseChildren = true;
            this._baseItem = new GoodsItem();
            this._baseItem.setOverPosition(-1, -1);
            this._baseItem.x = 2;
            this._baseItem.y = 2;
            this._baseItem.isShowLock = true;
            this._baseItem.setSize(32, 32);
            this._baseItem.doubleClickEnabled = true;
            this._baseItem.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClick);
            this._baseItem.addEventListener(flash.events.MouseEvent.DOUBLE_CLICK, this.onItemDoubleClick);
            this.addChild(this._baseItem);
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._baseItem.itemData = arg1 as ItemData;
            return;
        }

        /* internal  */onItemClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (arg1.ctrlKey && this._baseItem.itemData) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ChatShowItem, this._baseItem.itemData));
                arg1.stopImmediatePropagation();
                return;
            }
            if (this._baseItem.itemData && Cache.instance.shop.operType == ShopOperType.SALE) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopSellItem, this._baseItem.itemData.uid));
            }
            else if (this._baseItem.itemData && Cache.instance.shop.operType == ShopOperType.FIX) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ShopFixEquipment, {"posType": this._baseItem.itemData.posType, "itemData": this._baseItem.itemData}));
            }
            return;
        }

        /* internal  */onItemDoubleClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (data) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.PetEquipDress, data));
            }
            return;
        }

        /* internal */ /* var */_baseItem: GoodsItem;
    }
